<%@ page language="java" contentType="text/html; charset=UTF-8" import="web_hr.*,java.sql.*"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
	String id = request.getParameter("userid");
	Model emp = new Model("hr_employee");
	Object[] obj=emp.find("emp_id", id);
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./Res/Bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="./Res/Css/create.css">
<title>Insert title here</title>
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>

 <script>

$(document).ready(function(){
	if($("#hid").val()=="emp"){
		$("#emp").attr('checked',true);
	}else{
		$("#admin").attr('checked',true);
	}
	var flag =0;
	$("[name='basic_salary']").focusout(function(){
		if($(this).val().length==0 ){
			if(flag ==0){
				$("#w3").remove();
				$(this).after("<span id='warming3'><font color = red>basic_salary must be filled</font></span>");
				flag =1;
			}
		}else{
			$("#warming3").remove();	
			flag =0;
			$.ajax({
				type:"post",
				url:"./check_bsalary.jsp",
				data:{basic_salary:$("input[name='basic_salary']").val()},
				success:function(data,textStatus){
					$("#w3").remove();
					$("[name='basic_salary']").after(data);
				}
			});
		}
	});
});	

$(document).ready(function(){
	var flag =0;
	$("[name='age']").focusout(function(){
		if($(this).val().length==0 ){
			if(flag ==0){
				$("#w4").remove();
				$(this).after("<span id='warming4'><font color = green>Age can be null</font></span>");
				flag =1;
			}
		}else{
			$("#warming4").remove();	
			flag =0;
			$.ajax({
				type:"post",
				url:"./check_age.jsp",
				data:{age:$("input[name='age']").val()},
				success:function(data,textStatus){
					$("#w4").remove();
					$("[name='age']").after(data);
				}
			});
		}
	});
});	

$(document).ready(function(){
	var flag =0;
	$("[name='fname']").focusout(function(){
		if($(this).val().length==0 ){
			if(flag ==0){
				$("#w5").remove();
				$(this).after("<span id='warming5'><font color = red>firstname must be filled</font></span>");
				flag =1;
			}
		}else{
			$("#warming5").remove();	
			flag =0;
			$.ajax({
				type:"post",
				url:"./check_fname.jsp",
				data:{fname:$("input[name='fname']").val()},
				success:function(data,textStatus){
					$("#w5").remove();
					$("[name='fname']").after(data);
				}
			});
		}
	});
});

$(document).ready(function(){
	var flag =0;
	$("[name='lname']").focusout(function(){
		if($(this).val().length==0 ){
			if(flag ==0){
				$("#w6").remove();
				$(this).after("<span id='warming6'><font color = red>username must be filled</font></span>");
				flag =1;
			}
		}else{
			$("#warming6").remove();	
			flag =0;
			$.ajax({
				type:"post",
				url:"./check_lname.jsp",
				data:{lname:$("input[name='lname']").val()},
				success:function(data,textStatus){
					$("#w6").remove();
					$("[name='lname']").after(data);
				}
			});
		}
	});
});

$(document).ready(function(){
	$("#reset").click(function(){
		$("#warming1").remove();
		$("#w1").remove();
		$("#warming2").remove();
		$("#w2").remove();
		$("#warming3").remove();
		$("#w3").remove();
		$("#warming4").remove();
		$("#w4").remove();
		$("#warming5").remove();		
		$("#w5").remove();
		$("#warming6").remove();
		$("#w6").remove();
		
	});	
});	


</script> 
 
</head>
<body class="container">

<h2>Update Employee</h2>
	<form action="hr_update" method="post" class="form-inline">
		<input name="id" value=<%=id%> type="hidden">
		<div class="form-group">
			<label for="basic_salary">Primary Salary:</label><input class="form-control" id="basic_salary" name="basic_salary" type="text" <%="value="+obj[3]%>>
		</div><br/>
		
		<div class="form-group">
			<label for="fname">First Name:</label><input class="form-control" id="fname" name="fname" type="text" <%="value="+obj[5]%>>	
		</div><br/>
		
		<div class="form-group">
			<label for="lname">Last name:</label><input class="form-control" id="lname" name="lname" type="text" <%="value="+obj[4]%>>
		</div><br/>
		
		<div class="form-group">
			<label for="age">Age:</label><input class="form-control" id="age" name="age" type="text" <%="value="+obj[6]%>>	
		</div><br/>
		
		<div class="form-group">
			<label for="role">Role:</label>&nbsp;<input class="radio" id="admin" name="role"  type="radio"<%="value="+obj[7]%>><span>admin</span><input class="radio" id="emp" name="role"  type="radio" <%="value="+obj[7]%>><span>emp</span>		
		</div><br/>
		
		<input id="hid" type="hidden" value='<%=obj[7] %>'>	
		
		<input id="submit" class="btn  btn-primary" type="submit" value="submit" onclick="javascript:{this.disabled=true;document.form1.submit();}">
		<input id="reset" class="btn  btn-default" type="reset" value="reset">
	</form>	

</body>
</html>